package ca.tatham.senssim.pddd;

import java.util.HashSet;
import java.util.Set;

import ca.tatham.senssim.util.Address;

public class Level
{
  private int lambda = 0;
  /** alpha nodes: neighbors with lower lambda */
  private final Set<Address> m_parents = new HashSet<Address>();
  /** beta nodes: neighbors with same lambda */
  private final Set<Address> m_siblings = new HashSet<Address>();
  /** alpha nodes: neighbors with higher lambda */
  private final Set<Address> m_children = new HashSet<Address>();

  public Level()
  {

  }

  @Override
  public String toString()
  {
    return "<" + lambda + ',' + m_parents.size() + ',' + m_siblings.size()
        + '>';
  }

  public int sizeOf()
  {
    return 16;
  }

  public void updateSets(Level level, Address node)
  {
    if (level.lambda < lambda)
    {
      m_parents.add(node);
      m_siblings.remove(node);
      m_children.remove(node);
    }
    else if (level.lambda == lambda)
    {
      m_parents.remove(node);
      m_siblings.add(node);
      m_children.remove(node);
    }
    else
    {
      m_parents.remove(node);
      m_siblings.remove(node);
      m_children.add(node);
    }
  }

  public boolean haveParent()
  {
    return !m_parents.isEmpty();
  }

  public boolean haveSibling()
  {
    return !m_siblings.isEmpty();
  }

  public boolean haveChild()
  {
    return !m_children.isEmpty();
  }

  public Set<Address> getParents()
  {
    return m_parents;
  }

  public Set<Address> getSiblings()
  {
    return m_siblings;
  }

  public Set<Address> getChildren()
  {
    return m_children;
  }

  public int getLambda()
  {
    return lambda;
  }

  public void setLambda(int lambda)
  {
    this.lambda = lambda;
  }

}
